import java.util.ArrayList;
import java.util.List;

import com.google.gson.Gson;
import doujian.MatchManager;
import doujian.match.Match;
import doujian.model.Adult;
import doujian.model.Host;
import doujian.model.Room;
import doujian.model.Student;

public class AEMatchShell {

	private static String stuList;
	private static String hostList;

	public static void main(String[] args) {

		/**
		 * 硬性筛选
		 */
		testFilter();
		
		/**
		 * 最优匹配
		 */
		testMatch();
	}

	private static void testFilter() {
		Host h1 = new Host();
		h1.id = 101;

		Adult h1a1 = new Adult();
		h1a1.sex = 0;
		Adult h1a2 = new Adult();
		h1a2.sex = 1;
		List<Adult> adults = new ArrayList<Adult>();
		adults.add(h1a1);
		adults.add(h1a2);

		h1.adults = adults;

		Room h1r1 = new Room();
		h1r1.max_person = 1;
		Room h1r2 = new Room();
		h1r2.max_person = 2;
		List<Room> rooms = new ArrayList<Room>();
		rooms.add(h1r1);
		rooms.add(h1r2);
		h1.rooms = rooms;

		Host h2 = new Host();
		h2.id = 102;

		Adult h2a1 = new Adult();
		h2a1.sex = 0;
		List<Adult> h2adults = new ArrayList<Adult>();
		h2adults.add(h2a1);

		h2.adults = h2adults;

		Room h2r1 = new Room();
		h2r1.max_person = 2;
		List<Room> h2rooms = new ArrayList<Room>();
		h2rooms.add(h2r1);

		h2.rooms = h2rooms;

		Host h3 = new Host();
		h3.id = 103;

		Adult h3a1 = new Adult();
		h3a1.sex = 0;
		List<Adult> h3adults = new ArrayList<Adult>();
		h3adults.add(h3a1);

		h3.adults = adults;

		Room h3r1 = new Room();
		h3r1.max_person = 2;
		Room h3r2 = new Room();
		h3r2.max_person = 1;
		Room h3r3 = new Room();
		h3r3.max_person = 2;
		List<Room> h3rooms = new ArrayList<Room>();
//		h3rooms.add(h3r1);
		h3rooms.add(h3r2);
//		h3rooms.add(h3r3);
		
		h3.rooms = h3rooms;
		
		List<Host> hostList = new ArrayList<Host>();
		hostList.add(h1);
		hostList.add(h2);
		hostList.add(h3);
		
		Gson g = new Gson();
		
		
		List<Student> stuList = new ArrayList<Student>();
		
		Student s1 = new Student();
		s1.id = 202;
		s1.sex = 1;
		s1.numberOfPeople = 2;
		
		Student s2 = new Student();
		s2.id = 203;
		s2.sex = 0;
		s2.numberOfPeople = 4;
		
		Student s3 = new Student();
		s3.id = 204;
		s3.sex = 1;
		s3.numberOfPeople = 1;
		
		stuList.add(s1);
		stuList.add(s2);
		stuList.add(s3);
		
		String hostListStr = g.toJson(hostList);
		String stuListStr = g.toJson(stuList);
		
		System.out.println(hostListStr);
		System.out.println(stuListStr);
		
		System.out.println(MatchManager.getFilteredHostList(g.toJson(s1), hostListStr));
	}

	private static void testMatch() {
		
		stuList = "[\n" + "  {\n" + "    \"id\": 1,\n" + "    \"selections\": [ 4, 5]\n" + "  },\n" + "  {\n"
				+ "    \"id\": 2,\n" + "    \"selections\": [ 5 ]\n" + "  },\n" + "  {\n" + "    \"id\": 3,\n"
				+ "    \"selections\": [ 4, 5 ]\n" + "  }\n" + "]";

		hostList = "[\n" + "  {\n" + "    \"id\": 4,\n" + "    \"selections\": [ 1 ]\n" + "  },\n" + "  {\n"
				+ "    \"id\": 5,\n" + "    \"selections\": [ 1, 2 ]\n" + "  }\n" + "]";
		
		try {
			String ret = Match.removeOneWayEdge(stuList, hostList);
			System.out.println(Match.allocate(ret));
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}

}
